home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / make / icmake-6.000 / icmake-6 / icmake / exec / discard.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-08  |  1.4 KB  |  55 lines

  1. /*
  2. \funcref{discard}{VAR\_ discard (\params)}
  3.     {
  4.         {VAR\_} {v} {variable to discard}
  5.     }
  6.     {variable, possibly after discarding}
  7.     {}
  8.     {}
  9.     {discard.c}
  10.     {
  11.  
  12.         Function {\em discard()} may be called when a variable or
  13.         intermediate result is no longer needed. The function checks if the
  14.         type of the variable is {\em e\_list} or {\em e\_str}; if so, the
  15.         associated memory possibly may be freed.
  16.  
  17.         Whether the associated memory actually may be freed depends on the
  18.         {\em vu.i$\rightarrow$count} field of the variable; since several
  19.         variables may point to the same occupied memory. If this count is 1,
  20.         then memory actually may be freed.
  21.  
  22.         If the associated memory may not be freed due to multiple occupation,
  23.         then the {\em vu.i$\rightarrow$count} field is simply decreased.
  24.  
  25.     }
  26. */
  27.  
  28. #include "icm-exec.h"
  29.  
  30. VAR_ discard (v)
  31. VAR_ v;
  32. {
  33.     register unsigned
  34.         i;
  35.  
  36.     if ( (v.type & (e_str | e_list)) && v.vu.i && v.vu.i->count)
  37.     {
  38.         v.vu.i->count --;
  39.         if (! v.vu.i->count)
  40.         {
  41.             if (v.type & e_str)
  42.                 xrealloc (v.vu.i->ls.str, 0);
  43.             else
  44.             {
  45.                 for (i = 0; i < v.vu.i->ls.list.size; i++)
  46.                     xrealloc (v.vu.i->ls.list.element [i], 0);
  47.                 xrealloc (v.vu.i->ls.list.element, 0);
  48.             }
  49.             v.vu.i = xrealloc (v.vu.i, 0);
  50.         }
  51.     }
  52.  
  53.     return (v);
  54. }
  55.